package h0718;

import java.util.Scanner;

public class ReliableCars {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);

        String originFare = sc.nextLine();
        sc.close();
        int allFare = Integer.parseInt(originFare);
        int temp=allFare;

        int count=0;
        while (!originFare.equals("1")){
            if (originFare.contains("4")){
               count++;  //统计含有4的
            }
            originFare=String.valueOf(--temp);
        }
        System.out.println(allFare-count);
    }

}
